<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

class Restock extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'restock';
    public $timestamps = false;

    public function scopeSearch($query, $params)
    {

        if(!empty($params['manufacturer_id'])){
            $query->where('manufacturer_id', $params['manufacturer_id']);
        }

        if(!empty($params['goods_id'])){
            $query->where('goods_id', $params['goods_id']);
        }

        if(!empty($params['now_date'])){
            $query->where('now_date', [$params['now_date']]);
        }

        if(!empty($params['start_time']) && !empty($params['end_time'])){
            $query->whereBetween('now_date', [$params['start_time'],$params['end_time']]);
        }

        return $query;
    }

    public function manufacturer(){
        return $this->belongsTo(Manufacturer::class);
    }
    public function goods(){
        return $this->belongsTo(Goods::class);
    }


}
